<?php
	// initialize debug pre
	global $debug_pre_content, $nav_links, $trigger_uri, $document_root;
	
	// Initialize logging
	$debug_pre_content = array();
	
	// Set logging state
	$debug_pre_content[0] = "false";
	
	// Create list of links in navigation
	$nav_links = array('surplus', 'limits', 'modern-tools', 'daily', 'standards', '1160', 'media', 'about', 'contact');
	
	// Define root for file and directory requests
	$document_root = "http://".$_SERVER['HTTP_HOST']."";
	//$debug_pre_content[] = "document_root set to: $document_root";
	
	//$debug_pre_content[] = "Request URI: ".$_SERVER["REQUEST_URI"];
	
	// Take last parameter of request uri as trigger for page display
	$trigger_uri = array();
	$temp = preg_match("/\/[a-zA-Z\-\_0-9\?\=\&\.]+$/", $_SERVER["REQUEST_URI"], $trigger_uri);
	//$debug_pre_content[] = "Request uri after pregmatch: $trigger_uri[0]";
	$trigger_uri = str_replace("/", "", $trigger_uri[0]);
	
	// Extract GET variables from uri
	$temp2 = preg_match("/\?.+$/", $trigger_uri, $get_vars);
	$get_vars = $get_vars[0];
	if ($_GET) {
		foreach ($_GET as $key => $value) {
			$debug_pre_content[] = "GET vars are: $key = $value";
		}
	}
	
	// Clean the request uri from GET variables
	$trigger_uri = str_replace($get_vars, "", $trigger_uri);
	//$debug_pre_content[] = "Request uri after substitution: $trigger_uri";
	
	// Trigger the right content for the request uri
	if ($trigger_uri == "about") {
		$include_content = 'includes/about.php';
	} else if ($trigger_uri == "contact") {
		$include_content = 'includes/contact.php';
	} else if (in_array($trigger_uri, $nav_links)) {
		$include_content = 'includes/content.php';
	} else {
		header("Location: /surplus");
		exit();
	}
?>
<?php require("includes/header.php"); ?>
<body>
<div id="container">
	<!-- Include Header -->
	<?php require("includes/left_bar.php"); ?>
	<?php require($include_content); ?>
	<div class="clearfix"></div>
</div> <!--! end of #container -->

<?php require("includes/footer.php"); ?>